<?php

/**
 * 
 * @author taras
 */
class gLinker
{
	/**
	 * 
	 * Enter description here ...
	 * @var gDbo
	 */
	public $dbo;
	/**
	 * 
	 * Enter description here ...
	 * @var gApp
	 */
	public $app;
	/**
	 * 
	 * Enter description here ...
	 * @var gFile
	 */
	public $file;
	/**
	 * 
	 * Enter description here ...
	 * @var gSession
	 */
	public $session;
	/**
	 * 
	 * Enter description here ...
	 * @var gI18n
	 */
	public $i18n;
	/**
	 * 
	 * Enter description here ...
	 * @var gRouter
	 */
	public $router;
	/**
	 * 
	 * Enter description here ...
	 * @var gDoc
	 */
	public $doc;
	/**
	 * 
	 * Enter description here ...
	 * @var gView
	 */
	public $view;
	/**
	 * 
	 * Enter description here ...
	 * @var gUser
	 */
	public $user;
    /**
     *
     * @var gRequest
     */
    public $request;

	
	function __construct()
	{
		gCore::includeCoreObject('dbo');
		gCore::includeCoreObject('app');
		gCore::includeCoreObject('file');
		gCore::includeCoreObject('session');
		gCore::includeCoreObject('i18n');
		gCore::includeCoreObject('router');
		gCore::includeCoreObject('doc');
		gCore::includeCoreObject('view');
		gCore::includeCoreObject('user');
        gCore::includeCoreObject('request');
		$this->dbo = new gDbo( $this );
		$this->dbo->init();
		$this->app = new gApp( $this );
		$this->app->init();
		$this->file = new gFile($this);
		$this->file->init();
		$this->session = new gSession( $this );
		$this->session->init();
		$this->i18n = new gI18n( $this );
		$this->i18n->init();
		$this->router = new gRouter( $this );
		$this->router->init();		
		$this->doc = new gDoc( $this );
		$this->doc->init();
		$this->view = new gView( $this );
		$this->view->init();
		$this->user = new gUser( $this );
		$this->user->init();
        $this->request = new gRequest( $this );
        $this->request->init();
	}	
	/**
	 * 
	 * Enter description here ...
	 * @param unknown_type $key
	 */
	function __get($key)
	{
		if( gCore::includeCoreObject($key) )
		{
			$classname = 'g'.$key;
			$this->$key = new $classname(gInit::getInstance());
			$this->$key->init();
			
		}
		else
		{
			throw new Exception('Cannot load core file');
		}
		return $this->$key;
	}

    public function bindObject($name,$object)
    {
        $this->$name = $object;
    }

    public function createObject($name)
    {
        $classname = 'g'.ucfirst($name);
        $this->$name = new $classname ( $this );
        $this->$name->init();
        $this->pool[$name] = $this->$name;
        return $this->pool[$name];
    }

	function __call($key,$params)
	{
		
	}

	function __clone()
	{
		
	}
}